var fs = require('fs'),
		  os=require('os');

//获取CPU温度
exports.getCpuTemperature =function(req,res,next){
	
	fs.readFile('/sys/class/thermal/thermal_zone0/temp','utf-8',function(err,data){
			if(err){
					next(err);
				}
			 var val = parseInt(data)/1000;
			 res.json({cpuTemp:val.toFixed(1)});
		});
	
	};
	
		 //获取系统运行时长
	exports.getUptime = function(req,res,next){
		
		var uptime=os.uptime();
		
		var val = 0;
	    if(uptime<= 60){
					val = uptime + "秒";
			}else if(uptime>60 && uptime <=3600){
					val = (uptime /60 ) .toFixed(1)+  "分钟";
				}else if(uptime>3600 && uptime <=86400){
					val = (uptime /3600).toFixed(1)+  "小时";
				}else{
							val = (uptime /86400).toFixed(1) +  "天";
					}
		
		 res.json({uptime:val});
		 
		 
		 }
	

	
	//获取内存使用情况
exports.getMeminfo =function(req,res,next){
	
	var freemem = os.freemem()/1024/1024;
	var totalmem = os.totalmem()/1024/1024;
	var valJson = {
			freemem:freemem.toFixed(1),
			totalmem:totalmem.toFixed(1)
		}
	 res.json(valJson);
	}
